package com.iter.devbox.pattern.flyweight;

import java.util.HashMap;
import java.util.Map;

/**复合享元对象角色*/
public class ConcreteCompositeFlyweight implements Flyweight {
	/**状态所对应的享元对象的集合*/
	private Map<String, Flyweight> cache = new HashMap<String, Flyweight>();

	/**增加一个新的单纯享元对象到缓存中*/
	public void add(String key, Flyweight fly) {
		cache.put(key, fly);
	}

	/**一个具体操作，state是外部状态*/
	@Override
	public void operation(String state) {
		Flyweight fly = null;
		for (String o : cache.keySet()) {
			fly = cache.get(o);
			fly.operation(state);
		}
	}
}
